package com.hps.demo.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hps.demo.entity.Student;
import com.hps.demo.mapper.StudentMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author heps
 */
@RestController
@RequestMapping("/student")
public class StudentController {

    private StudentMapper studentMapper;

    public StudentController(StudentMapper studentMapper) {
        this.studentMapper = studentMapper;
    }

    @GetMapping("/{id}")
    public Student findById(@PathVariable("id") Integer id) {
        return studentMapper.selectByPrimaryKey(id);
    }

    @GetMapping
    public List<Student> findAll() {

        return studentMapper.selectAll();
    }

    @GetMapping("/page")
    public PageInfo<Student> findByPage() {
        PageHelper.startPage(1, 3);
        List<Student> studentPageInfo = studentMapper.selectAllByPage();
        return new PageInfo<>(studentPageInfo);
    }
}
